package api

import (
	"errors"
	"sieve_admin_server_userpass/pkg/json"
	ut "sieve_admin_server_userpass/pkg/util/time"
	"time"
)

type OpsData struct {
	Uid int
	Cnt int
}

func ReportUserOps(t time.Time, ops []*OpsData) error {
	j, err := json.Marshal(ops)
	if err != nil {
		return err
	}
	ret, err := reqApi("report_user_ops", map[string]string{
		"time": ut.FmtDate(t, "YmdH"),
		"data": string(j),
	})
	if err != nil {
		return err
	}
	if string(ret) == "OK" {
		return nil
	}
	return errors.New("unexpected return: " + string(ret))
}
